package com.qq.controller;

import com.qq.dto.ActionResult;
import com.qq.pojo.SysUser;
import com.qq.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserInfoController {
  @Autowired
    private UserInfoService userInfoService;
@RequestMapping("getSysUser")
    public List<SysUser> getUserInfo(){
    List<SysUser> userInfo = userInfoService.findUserInfo();
    System.out.println("bbbbbbb");
    return userInfo;
}

    /**
     * 搜索框
     * @param tel
     * @return
     */
    @RequestMapping("getfindTel")
    public List<SysUser> getfindTel(String tel) {


        System.out.println(tel);
        SysUser getByTel = userInfoService.findGetByTel(tel);
        System.out.println(getByTel);
        List list=new ArrayList();
        list.add(getByTel);
        return list;

    }

    /**
     * 删除会员
     * @param id
     * @return
     */
    @RequestMapping(value = "delUserInfo",method = RequestMethod.DELETE)
public ActionResult delUserInfo(int id){
userInfoService.deleteUserInfoById(id);
        return new ActionResult(200,"delete success",null);
}
/**
 * 根据查询用户
 */
@RequestMapping(value = "getUserINfoById/{id}",method = RequestMethod.GET)
public ActionResult getUserINfoById(@PathVariable("id") int id){
 SysUser user=   userInfoService.findGetById(id);
    return new ActionResult(200,"null",user);

}
/**
 * 修改用户
 */
@RequestMapping(value = "updateUserInfo",method = RequestMethod.PUT)
public ActionResult updateUserInfo(@RequestBody SysUser user){
    System.out.println(user);
    userInfoService.updateInfoUser(user);
    return new ActionResult(200,"update success",user);
}
}
